import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    cartList:[]
  },
  getters: {
  },
  mutations: {
    add(state,obj){
      obj.buy=true
      var index=state.cartList.findIndex(v=>v.id==obj.id)
      if(index==-1){
        obj.num=1;
        state.cartList.push(obj)
      }else{
        state.cartList[index].num +=1
      }
      console.log(state.cartList);
    }
  },
  actions: {
  },
  modules: {
  }
})
